import Foundation
import UIKit

extension SendMessageToWXReq {
    static func request(withText text: String?, orMediaMessage message: WXMediaMessage?, bText: Bool, inScene scene: WXScene) -> SendMessageToWXReq {
        let req = SendMessageToWXReq()
        req.bText = bText
        req.scene = Int32(scene.rawValue)
        if bText {
            req.text = text ?? ""
        } else {
            if let message = message { req.message = message }
        }
        return req
    }
}

class WXApiRequestHandler {
    // Public Methods
    static func sendText(_ text: String, in scene: WXScene) {
        let req = SendMessageToWXReq.request(withText: text, orMediaMessage: nil, bText: true, inScene: scene)
        WXApi.send(req)
    }
    
    static func sendImageData(_ imageData: Data, tagName: String?, messageExt: String?, action: String?, thumbImage: UIImage?, in scene: WXScene) {
        let ext = WXImageObject()
        ext.imageData = imageData
        
        let message = WXMediaMessage()
        message.mediaObject = ext
        message.messageExt = messageExt
        message.messageAction = action
        if let thumbImage = thumbImage {
            message.setThumbImage(thumbImage)
        }
        message.mediaTagName = tagName
        
        let req = SendMessageToWXReq.request(withText: nil, orMediaMessage: message, bText: false, inScene: scene)
        
        WXApi.send(req)
    }
    
}
